<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/icons-extra.css" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">	
			<a class="mui-icon mui-icon-back mui-action-back mui-pull-left"></a>
			<h1 class="mui-title ">Fingerprint</h1>
			<a class="mui-icon-extra mui-icon-extra-topic mui-pull-right" style="margin-top: 10px;"
				 onclick="openWindow('docFingerprint','../doc/fingerprint.html?v=20190621')"></a>
		</header>
		<div class="mui-content">
			<div class="mui-content-padded">
				<div class="mui-row">
					Fingerprint模块管理指纹识别。
				</div>
				<br />
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-success mui-btn-block" onclick="fingerpring()">指纹识别</button>
				</div>
				<br />
				<div class="mui-row" id="divInfo"></div>
			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script type="text/javascript" src="../js/app.js" ></script>
		<script type="text/javascript">
			mui.init();
			function outSet(message){
				document.getElementById("divInfo").innerText = message;
			}
			
			function outLine(message){
				var text = document.getElementById("divInfo").innerText;
				document.getElementById("divInfo").innerText = text + "\n" + message;
			}
			var isFingerprint = false;
			mui.plusReady(function(){
				// 检查是否支持指纹识别
				if(plus.fingerprint) {
					if(!plus.fingerprint.isSupport()) {
						outSet('此设备不支持指纹识别');
						return;
					}
					if(!plus.fingerprint.isKeyguardSecure()) {
						outSet('此设备未设置密码锁屏，无法使用指纹识别');
						return;
					}
					if(!plus.fingerprint.isEnrolledFingerprints()) {
						outSet('此设备未录入指纹，请到设置中开启');
						return;
					}
					isFingerprint = true;
					outSet('此设备支持指纹识别');
				}else {
					outSet('当前环境不支持指纹识别API，请更新到最新版本');
				}
			});
			
			// 指纹识别认证 
			function fingerpring() {
				if(isFingerprint == false){
					plus.nativeUI.toast('此设备指纹识别未准备！');
					return;
				}
				var waiting = null;
				// Android平台弹出等待提示框 
				if('Android'==plus.os.name) {
					plus.nativeUI.showWaiting('指纹识别中...');
				}
				plus.fingerprint.authenticate(function(){
					plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
					alert('指纹识别成功');
				}, function(e){
					switch(e.code) {
						case e.AUTHENTICATE_MISMATCH:
							plus.nativeUI.toast('指纹匹配失败，请重新输入');
							break;
						case e.AUTHENTICATE_OVERLIMIT:
							plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
							plus.nativeUI.alert('指纹识别失败次数超出限制，请使用其它方式进行认证');
							break;
						default:
							plus.nativeUI.closeWaiting();//兼容Android平台关闭等待框
							plus.nativeUI.alert('指纹识别失败('+e.code+')，请重试');
							break;
					}
				});
				
			}
		</script>
	</body>

</html>